﻿''' <summary>
''' Provides extension methods to the <see cref="Integer">Integer</see> object.
''' </summary>
''' <revisions>
'''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
''' </revisions>
Public Module IntegerExtensions

  ''' <summary>
  ''' Formats the inputed content length to display to the nearest data size element.
  ''' </summary>
  ''' <param name="value">The value.</param>
  ''' <returns>A <see cref="String">String</see> with the specified content length formatted to the nearest data size element.</returns>
  ''' <example>
  '''   <para>The following examples display the number of bytes of file.</para>
  '''   <code language="vb">
  '''     Public Sub DisplayFileSize(ByVal FilePath As String)
  '''       MsgBox(Convert.ToInt32(My.Computer.FileSystem.GetFileInfo(FilePath).Length).ContentLength)
  '''     End Sub
  '''   </code>
  '''   <code language="c#">
  '''     public void DisplayFileSize(string FilePath)
  '''     {
  '''     	MsgBox(Convert.ToInt32(My.Computer.FileSystem.GetFileInfo(FilePath).Length).ContentLength);
  '''     }
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function ContentLength(ByVal value As Integer) As String
    If value < 1024 Then
      Return FormatNumber(value, 0) & " bytes"
    ElseIf value >= 1024 And value < 1048576 Then
      Return FormatNumber((value / 1024)) & " KB"
    ElseIf value >= 1048576 And value < 1073741824 Then
      Return FormatNumber(((value / 1024) / 1024)) & " MB"
    Else
      Return FormatNumber((((value / 1024) / 1024) / 1024)) & " GB"
    End If
  End Function

End Module